<?php

/**
 * Unit
 */
class Controller_Unit extends Controller_Abstract
{
    function actionIndex()
    {
       
    }

	
    function actionList(){
    
    	$page = $this->_context->param('page',1);
    	$page_size = $this->_context->param('row',10);
    	$list = Unit::find()->asArray()->limitPage($page, $page_size)->getAll();
    	
    	return json_encode($list);
    
    }
    
    function actionNew(){
    	
    	$unit = new Unit($_POST);
    	
	    if ($unit->save()){
			echo json_encode(array('success'=>true));
		} else {
			echo json_encode(array('errorMsg'=>'系统出错,操作未能完成.'));
		}
    }
    function actionUpdate(){
    	$id=$this->_context->post('unit_id');
    	$unit = Unit::find('unit_id=?',$id)->getOne();
    	
    	$unit->changeProps($_POST);
    	
    	try{
    		$unit->save();
    		return  json_encode(array('success'=>true));
    	}
    	catch (Exception $e){
    		return json_encode(array('errorMsg'=>'系统出错,操作未能完成.'));
    	}
    }
    
    function actionDestroy(){
    	
    	$id=$this->_context->post('id',0);
    	$row=Unit::find("unit_id=?",$id)->getOne();

    	try {
    		$row->destroy();
			return  json_encode(array('success'=>true));
    	}
    	catch (Exception $e){
				return json_encode(array('errorMsg'=>'系统出错,操作未能完成.'));
		}
    }
}

